package com.sale.system.service.impl;

import com.sale.common.core.domain.model.LoginUser;
import com.sale.common.enums.YesOrNoEnum;
import com.sale.common.utils.SecurityUtils;
import com.sale.system.domain.SysDayReport;
import com.sale.system.mapper.DayReportMapper;
import com.sale.system.service.IDayReportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 工作日报记录
 *
 * @author zhangyingdong
 * @version 1.0.0
 * @package com.sale.system.service.impl
 * @className DayReportServiceImpl
 * @date 2022-01-24  00:23
 */
@Service
public class DayReportServiceImpl implements IDayReportService {

    @Resource
    private DayReportMapper dayReportMapper;
    /**
     * 查询日报列表
     *
     * @param sysDayReport
     * @return List<SysDayReport>
     * @throws
     * @method list
     * @author zhangyingdong
     * @date 2022/1/24 0:47
     */
    @Override
    public List<SysDayReport> selectDayReportList(SysDayReport sysDayReport) {
        return dayReportMapper.selectDayReportList(sysDayReport);
    }

    /**
     * 新增工作日报
     *
     * @param sysDayReport
     * @return int
     * @throws
     * @method addDayReport
     * @author zhangyingdong
     * @date 2022/1/24 0:49
     */
    @Override
    public int addDayReport(SysDayReport sysDayReport) {

        //TODO: 暂时给默认值
        sysDayReport.setDelInd(YesOrNoEnum.NO.getCodeStr());

        LoginUser loginUser = SecurityUtils.getLoginUser();
        sysDayReport.setCreateBy(loginUser.getUsername());
        sysDayReport.setCreateTime(new Date());
        return dayReportMapper.insert(sysDayReport);
    }

    /**
     * 修改工作日报
     *
     * @param sysDayReport
     * @return int
     * @throws
     * @method update
     * @author zhangyingdong
     * @date 2022/1/24 0:49
     */
    @Override
    public int update(SysDayReport sysDayReport) {
        return dayReportMapper.updateByPrimaryKeySelective(sysDayReport);
    }

    /**
     * 删除工作日报
     *
     * @param id
     * @return int
     * @throws
     * @method delete
     * @author zhangyingdong
     * @date 2022/1/24 0:52
     */
    @Override
    public int delete(Long id) {
        SysDayReport report = new SysDayReport();
        report.setId(id);
        report.setDelInd(YesOrNoEnum.YES.getCodeStr());
        return dayReportMapper.updateByPrimaryKeySelective(report);
    }

    @Override
    public SysDayReport selectById(Long id) {
        return dayReportMapper.selectByPrimaryKey(id);
    }
}
